<template>
  <div class="content">
    <div class="menu-area">
      <div
        v-for="(item, index) in menuList"
        :key="index"
        class="menuCard"
        @click="jump(item)"
      >
        <svg-icon v-if="item.meta?.icon === ''" icon-class="system" />
        <i
          v-if="item.meta?.icon && item.meta?.icon.includes('el-icon')"
          :class="item.meta?.icon"
        ></i>
        <SvgIcon v-else-if="item.meta?.icon" :icon-class="item.meta?.icon" />
        <div class="title">{{ item.meta.title }}</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { usePermissionStoreHook } from "@/store/modules/permission";
import router from "@/router";
// 获取首页菜单
const menuStore = usePermissionStoreHook();
const menu = ref(menuStore.routes);
const menuList = ref();

onMounted(() => {
  // 获取菜单列表
  const list = menu.value.filter((item) => item.name === "WINDOW7")[0]
    ?.children;
  // 筛选需要显示的菜单
  menuList.value = list?.filter((item) => item?.meta?.hidden === false);
});
// 首页跳转
async function jump(item: any) {
  console.log("item", item);
  if (item.enabled === 0) {
    ElMessage({
      showClose: true,
      message: "菜单暂未启用",
      type: "warning",
    });
  } else {
    if (item.meta.permissionType === 1) {
      router.push({
        path: item.path,
      });
    } else {
      ElMessage({
        showClose: true,
        message: "目录不可点击",
        type: "warning",
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 20px 0 20px;
}

.menu-area {
  /*设置为grid网格布局*/
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 22% 22% 22% 22%;
  grid-gap: 12px;
  justify-content: center;
  .menuCard {
    padding-top: 35px;
    border-radius: 16px;
    text-align: center;
    height: 120px;
    cursor: pointer;
    background-image: linear-gradient(
      180deg,
      #2c92fb 0%,
      #2c92fb 53%,
      #33aaff 100%
    );

    svg {
      font-size: 30px;
      color: #fff;
    }
    .title {
      margin-top: 10px;
      padding-bottom: 30px;
      font-size: 15px;
      color: #fff;
    }
  }
}

.title {
  font-size: 36px;
  color: #8f8f94;
}
</style>
